﻿using System;

namespace MuXue.Zyiz.Template.Common.Redis
{
    /// <summary>
    /// 缓存时间，单位秒
    /// </summary>
    public class RedisCacheTime
    {
        /// <summary>
        /// 一小时
        /// </summary>
        public const int Hour = 3600;

        /// <summary>
        /// 一天
        /// </summary>
        public const int Day = 86400;

        /// <summary>
        /// 一周
        /// </summary>
        public const int Week = 604800;

        /// <summary>
        /// 一个月（30天）
        /// </summary>
        public const int Month = 2592000;

        /// <summary>
        /// 1分钟
        /// </summary>
        public const int Minute1 = 60;

        /// <summary>
        /// 5分钟
        /// </summary>
        public const int Minute5 = 300;

        /// <summary>
        /// 10 分钟
        /// </summary>
        public const int Minute10 = 600;

        /// <summary>
        /// 30分钟
        /// </summary>
        public const int HalfHour = 1800;

        /// <summary>
        /// 当前小时结束过期
        /// </summary>
        /// <returns></returns>
        public static int NowHour
        {
            get
            {
                DateTime now = DateTime.Now;
                int endSecond = (now.Hour + 1) * 60 * 60;
                int nowSecond = (now.Hour * 60 * 60) + (now.Minute * 60) + now.Second;
                return endSecond - nowSecond;
            }
        }

        /// <summary>
        /// 当天结束过期
        /// </summary>
        /// <returns></returns>
        public static int NowDay
        {
            get
            {
                DateTime now = DateTime.Now;
                int endSecond = 24 * 60 * 60;
                int nowSecond = (now.Hour * 60 * 60) + (now.Minute * 60) + now.Second;
                return endSecond - nowSecond;
            }
        }

        /// <summary>
        /// 当月结束过期
        /// </summary>
        /// <returns></returns>
        public static int NowMonth
        {
            get
            {
                DateTime now = DateTime.Now;
                int days = DateTime.DaysInMonth(now.Year, now.Month); // 当月天数
                int endSecond = days * 24 * 60 * 60;
                int nowSecond = (now.Day * 24 * 60 * 60) + (now.Minute * 60) + now.Second;
                return endSecond - nowSecond;
            }
        }
    }
}